package com.office.forum.manage.following.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.office.forum.manage.following.domain.FollowingUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.office.common.annotation.Log;
import com.office.common.core.controller.BaseController;
import com.office.common.core.domain.AjaxResult;
import com.office.common.enums.BusinessType;
import com.office.forum.manage.following.domain.ForumFollowing;
import com.office.forum.manage.following.service.IForumFollowingService;
import com.office.common.utils.poi.ExcelUtil;
import com.office.common.core.page.TableDataInfo;

/**
 * 用户关注表Controller
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/forum/following")
public class ForumFollowingController extends BaseController
{
    @Autowired
    private IForumFollowingService forumFollowingService;

    /**
     * 查询用户关注表列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ForumFollowing forumFollowing)
    {
        startPage();
        List<ForumFollowing> list = forumFollowingService.selectForumFollowingList(forumFollowing);
        return getDataTable(list);
    }

//    userId查询关注用户
    @GetMapping("/query")
    public TableDataInfo listFollowedId(ForumFollowing forumFollowing)
    {
        startPage();
        List<ForumFollowing> list = forumFollowingService.selectForumFollowedList(forumFollowing);
        return getDataTable(list);
    }


    /**
     * 获取用户关注表详细信息
     */
    @GetMapping(value = "/{followingId}")
    public AjaxResult getInfo(@PathVariable("followingId") Long followingId)
    {
        return success(forumFollowingService.selectForumFollowingByFollowingId(followingId));
    }

    /**
     * 新增用户关注表
     */
    @Log(title = "用户关注表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ForumFollowing forumFollowing)
    {
        return toAjax(forumFollowingService.insertForumFollowing(forumFollowing));
    }

    /**
     * 修改用户关注表
     */
    @Log(title = "用户关注表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ForumFollowing forumFollowing)
    {
        return toAjax(forumFollowingService.updateForumFollowing(forumFollowing));
    }

    /**
     * 删除用户关注表
     */
    @Log(title = "用户关注表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{followingIds}")
    public AjaxResult remove(@PathVariable Long[] followingIds)
    {
        return toAjax(forumFollowingService.deleteForumFollowingByFollowingIds(followingIds));
    }

    /**
     * 获取被关注用户的头像有名称
     */
    @GetMapping("userId")
    public TableDataInfo listFollowedUser( Long id)
    {
        startPage();
        List<FollowingUser> list = forumFollowingService.selectForumFollowedUser(id);
        return getDataTable(list);
    }

}
